<template>
	<view :data-theme="themeStyle">
		<mescroll-uni @getData="getData" refs="mescroll" :size="10" v-if="addonIsExit.presale">
			<block slot="list">
				<ns-adv keyword="NS_PINTUAN"></ns-adv>
				<view class="presale-page">
					<view class="presale-list" v-if="dataList.length">
						<ns-goods-item-col :value="dataList" @toDetail="toDetail" type="presale"></ns-goods-item-col>
					</view>
				</view>
				<view v-if="!dataList.length"><ns-empty :fixed="!1"></ns-empty></view>
			</block>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
		<ns-show-toast></ns-show-toast>
	</view>
</template>

<script>
import nsAdv from '@/components/ns-adv/ns-adv.vue';
import globalConfig from '@/common/js/golbalConfig.js';
import nsGoodsItemCol from '@/components/ns-goods-item/ns-goods-item-col.vue'
import nsShowToast from '@/components/ns-show-toast/ns-show-toast.vue'
export default {
	components: {
		nsAdv,
		nsGoodsItemCol,
		nsShowToast
	},
	data() {
		return {
			dataList: []
		};
	},
	mixins:[globalConfig],
	onLoad(options) {},
	onShow() {
		// 刷新多语言
		if(!this.addonIsExit.presale){
			this.$util.showToast({
				title:'预售插件未安装',
				mask:true,
				duration:2000
			})
			setTimeout(()=>{
				this.$util.redirectTo('/pages/index/index/index',{},'redirectTo')
			},2000)
			return;
		}
		this.$langConfig.refresh();
	},
	methods: {
		getData(mescroll) {
			this.$api.sendRequest({
				url: '/presale/api/goods/page',
				data: {
					page_size: mescroll.size,
					page: mescroll.num
				},
				success: res => {
					let newArr = [];
					let msg = res.message;
					if (res.code == 0 && res.data) {
						newArr = res.data.list;
					} else {
						this.$util.showToast({ title: msg });
					}
					mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail() {
					//联网失败的回调
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		toDetail(e) {
			this.$util.redirectTo('/promotionpages/presale/detail/detail', {
				id: e.presale_id
			});
		},
		imageError(index) {
			this.dataList[index].sku_image = this.$util.getDefaultImage().default_goods_img;
			this.$forceUpdate();
		}
	}
};
</script>

<style lang="scss">
.presale-top {
	width: 100%;

	image {
		width: 100%;
	}
}

.presale-page {
	width: 100%;
	box-sizing: border-box;

	.presale-use {
		width: 100%;
		padding: $ns-padding;
		box-sizing: border-box;
		border-radius: $ns-border-radius;
		background: #ffffff;

		.use-title {
			width: 100%;
			margin-bottom: $ns-margin;
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 50rpx;
			}

			text {
				padding: 0 $ns-padding;
			}
		}

		.use-step {
			display: flex;
			justify-content: center;
			align-items: center;

			.step-con {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				line-height: 0;
				border-radius: 100%;
				font-size: $ns-font-size-base;
				width: 100rpx;

				.step-title {
					color: $ns-text-color-gray;
					line-height: 1.2;
					font-size: $ns-font-size-base;
				}

				.step-con-icon {
					width: 100%;
					height: 90rpx;
					line-height: 90rpx;
					text-align: center;
				}

				.iconfont {
					font-size: 68rpx;
				}
				.iconyaoqing {
					font-size: 68rpx;
				}
				.iconfahuodai {
					font-size: 72rpx;
				}
			}

			.next-step {
				width: 60rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 0 14rpx;

				view {
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
				}

				view:nth-child(1) {
					opacity:0.2;
				}

				view:nth-child(2) {
					opacity:0.5;
				}

				view:nth-child(3) {
					opacity:0.8;
				}
			}
		}
	}

	.presale-list {
		.list-item {
			
		}
	}
}

.presale_game {
	width: 100%;
}

.empty {
	margin-top: 100rpx;
}
</style>
